/* eslint-disable camelcase */
/* eslint-disable no-tabs */
import request from '@/utils/request'

export const artcategoryGet = () => {
  return request.get('/my/cate/list')
}

// eslint-disable-next-line camelcase
export const artcategoryAdd = ({ cate_name, cate_alias }) => {
  return request.post('/my/cate/add', {
    cate_name, cate_alias
  })
}

export const artcategoryDel = (id) => {
  return request.delete('/my/cate/del', {
    params: { id }
  })
}

export const artcategoryGetById = (id) => {
  return request.get('/my/cate/info', {
    params: {
      id
    }
  })
}

// eslint-disable-next-line camelcase
export const artcategoryEdit = ({ id, cate_name, cate_alias }) => {
  return request.put('/my/cate/info', {
    id,
    cate_name,
    cate_alias
  })
}

// pagenum	是	number	页码值	整数，最小值为 1
// pagesize	是	number	每页显示多少条数据	整数，最小值为 1
// cate_id	否	string	文章分类的 id	整数，最小值为 1
// state

// eslint-disable-next-line camelcase
export const artListGetByQ = ({ pagenum, pagesize, cate_id, state }) => {
  return request.get('/my/article/list', {
    params: {
      pagenum,
      pagesize,
      cate_id,
      state
    }
  })
}

export const delArticleById = id => {
  return request.delete('/my/article/info', {
    params: {
      id
    }
  })
}

export const ArticleDetailGetById = id => {
  return request.get('/my/article/info', {
    params: {
      id
    }
  })
}

// title	是	string	文章标题	1-30 个字符
// cate_id	是	int	所属分类 Id	整数，最小值为 1
// content	是	string	文章内容	非空的字符串
// state	是	string	文章的发布状态	可选值为：已发布、草稿
// cover_img	是	blob二进制	文章封面	只能是图片文件

export const pubArticle = ({
  title,
  cate_id,
  content,
  state,
  cover_img
}) => {
  const fm = new FormData()
  fm.append('title', title)
  fm.append('cate_id', cate_id)
  fm.append('content', content)
  fm.append('state', state)
  fm.append('cover_img', cover_img)
  return request.post('/my/article/add', fm)
}
